package com.eds.config;

import com.eds.conusmer.NotificationConsumer;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @ClassName：DeadLetterConfig
 * @Author: vvSmile
 * @Date: 2025/04/08
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
@Configuration
public class DeadLetterConfig {
    //死信交换机
    @Bean
    public DirectExchange dlxExchange() {
        return new DirectExchange(NotificationConsumer.DLX_EXCHANGE);
    }

    //死信队列
    @Bean
    public Queue dlxQueue() {
        return new Queue(NotificationConsumer.DLX_QUEUE);
    }

    //绑定死信队列到死信交换机
    @Bean
    public Binding dlxBinding() {
        return BindingBuilder.bind(dlxQueue())
                .to(dlxExchange())
                .with(NotificationConsumer.DLX_ROUTING_KEY);
    }
}
